package com.aaa.PController;

import com.aaa.Entity.Product;
import com.aaa.Service.ProductService;
import com.aaa.util.DefaultMsg;
import com.aaa.util.TableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/toList")
    public String toList(){
        return "product";
    }


    @RequestMapping("productListAll")
    @ResponseBody
    public TableData listAll(Integer page, Integer limit){
        TableData tableData = productService.listAll(page, limit);
        return tableData;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public DefaultMsg delete(Integer id){
        String a="1";
        DefaultMsg delete = productService.Delete(id);
        return delete;
    }
    @RequestMapping("/AddOrUpdate")
    @ResponseBody
    public DefaultMsg  AddOrUpdate(Product product){
        DefaultMsg defaultMsg = productService.AddOrUpdate(product);
        return defaultMsg;
    }

    @RequestMapping("/product")
    public String ProductListAll(){
        return "product";
    }
//
}
